package com.ccloud.im.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ccloud.common.im.model.CIMSession;
import com.ccloud.im.mapper.UserSessionMapper;
import com.ccloud.im.domain.UserSession;
import com.ccloud.im.service.IUserSessionService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * Im 实时在线用户信息表 服务实现类
 * </p>
 *
 * @author chentl123
 * @since 2020-09-07
 */
@Service
public class UserSessionServiceImpl extends ServiceImpl<UserSessionMapper, UserSession> implements IUserSessionService {

    @Override
    public void save(CIMSession cimSession) {
        UserSession us = UserSession.convert(cimSession);
        us.insert();
    }

    @Override
    public UserSession get(CIMSession cimSession) {
        return UserSession.convert(cimSession);
    }

    @Override
    public void remove(String nioId) {
        UpdateWrapper<UserSession> wrapper = new UpdateWrapper<>();
        wrapper.eq("nid", nioId);
        this.baseMapper.delete(wrapper);
    }

    @Override
    public void clear() {
        UpdateWrapper<UserSession> wrapper = new UpdateWrapper<>();
        wrapper.gt("id",0);
        this.baseMapper.delete(wrapper);
    }
}
